﻿Type=Service
Version=3.15
@EndOfDesignText@
#Region  Service Attributes 
	#StartAtBoot: False
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Dim Notif As Notification
	Dim TZData As String
	Dim V_RYBM As String
	Dim HttpJobTool As HttpJob
	
End Sub
Sub Service_Create
'   Notif.Initialize
'   Notif.Icon = "icon"
'   Notif.SetInfo("移动查询","暂无通知",XTTZInfo)
'   Notif.Sound = False
'	 Notif.AutoCancel =True
'   Notif.Notify(1)   
'   Service.StartForeground(1,Notif)
End Sub

Sub Service_Start (StartingIntent As Intent)
 StartServiceAt("", DateTime.Now + PublicVar.GV_XTTZ_RefreshTime * DateTime.TicksPerSecond, False)
' RefreshNotification
End Sub

Sub Service_Destroy
	
End Sub

Sub RefreshNotification
	Dim sURL,sSession,sRYBM,sText As String
	
	sSession = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserSession)
	
	sRYBM = PublicVar.GV_DesTool.Base64encrypt(V_RYBM)
	
	sText = "Session=" & sSession & "&RYBM=" & sRYBM

	sURL = PublicVar.GetServerUrl&"/getrytzlist"
	HttpJobTool.Initialize("Job1",Me)
	HttpJobTool.PostString(sURL,sText)	
	
End Sub

Sub JobDone (Job As HttpJob)
   If Job.Success = True Then
      If Job.JobName = "Job1" Then
				HttpJobSuccess(Job)
      End If
   Else
		HttpJobError(Job)
   End If
   Job.Release
End Sub

Sub HttpJobSuccess(Job As HttpJob) 
	Dim sResult,sCode,sData As String
	Dim mapResult As Map
	
	ProgressDialogHide
	sResult = Job.GetString.Trim
	
	PublicVar.GV_JSonTool.Initialize(sResult)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sCode = mapResult.Get("Code")
	If sCode<>"0" Then
		sResult = mapResult.Get("Message")
		ToastMessageShow("获取数据失败"&CRLF &sResult, True)	
		Return
	End If
	
	sData = mapResult.Get("Data")
	If sData ="" Then
	
		Return	
	End If
	
	TZData = sData
	Notif.SetInfo("移动查询","您有新的通知",XTTZInfo)
	Notif.Cancel(1)
	Notif.Notify(1)
'	CallSub(XTTZInfo,"SetTZData")
	
End Sub

Sub HttpJobError(Job As HttpJob) 
	Dim sMsg As String
	ProgressDialogHide
	
	Log("Error: " & Job.ErrorMessage)
'	sMsg = "获取通知内容失败."& CRLF & Job.ErrorMessage 
'  ToastMessageShow(sMsg, True)
End Sub
